#include "Student.h"

int main(){
	Database db;
	int authenticationIsGood;
	string username, password;
	do {
		cout << endl << endl << endl <<"Welcome to Assn3" <<endl;
		cout << "================" << endl << endl;
		cout << "Please enter username: ";
		getline(cin, username);
		cin.clear();
		cin.sync();
		cout << "Please enter password: ";
		cin >> password;
		cin.clear();
		cin.sync();
		cout << endl;
		authenticationIsGood = db.authenticate(username, password);
		if (authenticationIsGood == WRONG_PASSWORD){
			cout << "Wrong password."<< endl << "Please try again." << endl <<endl;
			cin.ignore();
		}
		else if(authenticationIsGood == WRONG_USERNAME){
			cout << "Wrong username."<< endl <<"Please try again."<< endl << endl;
			cin.ignore();			
		}
		else if(authenticationIsGood == ACCOUNT_LOCKED){
			cout << "Please contact the any administrator to have your account unlocked."<<endl<<endl;
			exit(-1);			
		}
	}while(authenticationIsGood != SUCCESS);
	

	db.populate(username);

	cout << "------------------------------------------------------------------------" << endl << endl;

	if (db.getType() == "ADMIN"){
		Admin aAdmin(db);
		aAdmin.adminMenu();
	}

	if (db.getType() == "STUDENT"){
		Student aStudent(db);
		aStudent.studentMenu();
	}

	if (db.getType() == "LECT"){
		Lecturers aLecturer(db);
		aLecturer.lectMenu();
	}

	return 0;
}

void press_enter() {
    string temp;
    cout << endl << "Press Enter to continue...";
    getline (cin,temp);
    cin.ignore(10000, '\n');
    cin.clear();
    cin.sync();
    cout << endl;
}
